using System;
using System.Collections.Generic;
using System.Text;
using Fieldbook.Entities;
using Fieldbook.DAL;
using Fieldbook.Common;

namespace Fieldbook.Business
{
    public static class MachineController
    {
        public static List<MachineCategory> LoadMachineCategories(long userID)
        {
            List<MachineCategory> res = null;
            try
            {
                res = MachineCategoryDAO.LoadMachineCategories(userID);
            }
            catch (Exception ex)
            {
                LogManager.LogException("Error loading machine categories", ex);
            }
            return res;
        }

        public static bool InsertMachineCategory(MachineCategory category)
        {
            bool res = false;
            try
            {
                res = MachineCategoryDAO.InsertMachineCategory(category);
            }
            catch (Exception ex)
            {
                LogManager.LogException("Error inserting machine category", ex);
            }
            return res;
        }

        public static bool InsertMachineCategory(string description)
        {
            MachineCategory category = new MachineCategory();
            category.Description = description;
            return InsertMachineCategory(category);
        }

        public static bool InsertMachineCategory(string description, long userID)
        {
            bool res = false;
            try
            {
                long? houseHoldID = HouseholdDAO.GetHouseHoldID(userID);
                if (houseHoldID != null)
                {
                    MachineCategory category = new MachineCategory();
                    category.Description = description;
                    category.HouseHoldID = houseHoldID;
                    res = InsertMachineCategory(category);
                }
            }
            catch (Exception ex)
            {
                LogManager.LogException("Error inserting machine category", ex);
            }
            return res;
        }

        public static List<Machine> LoadMachines(long userID)
        {
            List<Machine> res = null;
            try
            {
                res = MachineDAO.LoadMachines(userID);
            }
            catch (Exception ex)
            {
                LogManager.LogException("Error loading machines", ex);
            }
            return res;
        }

        public static List<Machine> LoadMachines(long userID, long categoryID)
        {
            List<Machine> res = null;
            try
            {
                res = MachineDAO.LoadMachines(userID, categoryID);
            }
            catch (Exception ex)
            {
                LogManager.LogException("Error loading machines", ex);
            }
            return res;
        }

        public static bool InsertMachine(Machine machine)
        {
            bool res = false;
            try
            {
                res = MachineDAO.InsertMachine(machine);
            }
            catch (Exception ex)
            {
                LogManager.LogException("Error inserting machine", ex);
            }
            return res;
        }
    }
}
